package com.yuyou.fn.tms.controller;


import com.yuyou.fn.tms.service.IRegService;
import com.yuyou.fn.tms.util.Signs;
import com.yuyou.fn.tms.vo.CheckPermissionParam;
import com.yuyou.fn.tms.vo.CheckSignUpParam;
import com.yuyou.fn.tms.vo.ResponseResult;
import com.yuyou.fn.tms.vo.TmsCheckPermissionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;

@Controller
@RequestMapping("/api/data/student")
@Api(tags = "报名")
public class RegController {

    @Value("${tms.sign.key}")
    private String signKey ;

    @Resource
    private IRegService regService ;

    @ApiOperation(value = "检查是否能够报名校验接口")
    @RequestMapping(value = "/checkSignUp" , method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<String> checkSignUp(@RequestBody @Valid CheckSignUpParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        regService.checkSignUp(requestParam);
        return ResponseResult.success("OK") ;
    }

    @ApiOperation(value = "检查是否满足分层条件接口")
    @RequestMapping(value = "/checkPermission" , method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<TmsCheckPermissionResult> checkPermission(@RequestBody @Valid CheckPermissionParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        TmsCheckPermissionResult result  =  regService.checkPermission(requestParam);
        return ResponseResult.success(result) ;
    }

}
